package SellTest;

public class SellTicket implements Runnable {
    int maxCount = 300;

    @Override
    public void run() {
        while (true){
        sellTicket();
        if (maxCount <= 0) {
            return;
        }
    }
}
    private synchronized void sellTicket() {
        if (maxCount > 0) {
            System.out.println(Thread.currentThread().getName() + "卖出电影票为" + maxCount);
            maxCount--;
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
